package com.tj.collection.controller.admin.response;

import com.fqgj.common.api.ResponseData;
import com.fqgj.common.utils.CollectionUtils;
import com.qianli.cashmama.product.facade.result.ProductCategory;
import com.tj.collection.db.admin.entity.AuthAdminProductEntity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Created with IntelliJ IDEA.
 * User: sm
 * Date: 2017/9/6
 * Time: 下午9:07
 */
public class AdminProductCategoryResponse implements ResponseData {

    private List<Map<String, String>> list = new ArrayList<>();

    public AdminProductCategoryResponse(List<AuthAdminProductEntity> authAdminProductEntityList, List<ProductCategory> categoriesOfCurrentCategory) {
        if (CollectionUtils.isEmpty(authAdminProductEntityList) || CollectionUtils.isEmpty(categoriesOfCurrentCategory)) {
            return;
        }

        List<String> categoriesAvilable = categoriesOfCurrentCategory.parallelStream().map(ProductCategory::getCode).collect(Collectors.toList());

        for (AuthAdminProductEntity authAdminProductEntity : authAdminProductEntityList) {
            if (!categoriesAvilable.contains(authAdminProductEntity.getProductType())) {
                continue;
            }
            Map<String, String> temp = new HashMap<>();
            temp.put("productCategory", authAdminProductEntity.getProductType());
            temp.put("productCategoryName", authAdminProductEntity.getProductType());
            list.add(temp);
        }
    }

    public AdminProductCategoryResponse(List<ProductCategory> categoriesOfCurrentCategory) {
        for (ProductCategory productCategory : categoriesOfCurrentCategory) {
            Map<String, String> temp = new HashMap<>();
            temp.put("productCategory", productCategory.getCode());
            temp.put("productCategoryName", productCategory.getCode());
            list.add(temp);
        }
    }
}
